package cn.com.hhrcw.enterprise.web;

import cn.com.hhrcw.enterprise.params.CvResumeParams;
import cn.com.hhrcw.enterprise.vo.CvResumeVO;
import cn.com.hhrcw.entity.CvResume;
import cn.com.hhrcw.mapstruct.CvResumeConvert;
import cn.com.hhrcw.service.ICvResumeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.function.Function;

/**
 * 简历-简历
 *
 * @author gaoruiyi
 * @since 2020-11-07
 */
@RestController("CvResumeEntController")
@Slf4j
@RequestMapping("/en/cvResume")
@Api(tags = "简历-简历本历")
@Validated
public class CvResumeController extends JeecgController<CvResume, ICvResumeService> {

    @Autowired
    private ICvResumeService cvResumeService;

    @Autowired
    private CvResumeConvert cvResumeConvert;

    /**
     * 查询用户简历接口
     *
     * @param params 请求参数
     * @return
     */
    @GetMapping(value = "/list2")
    @AutoLog(logType = 2, ty = "visit", value = "查询简历列表")
    public Result<Page<CvResumeVO>> list2(CvResumeParams params, HttpServletRequest request) {
        QueryWrapper<CvResume> queryWrapper = QueryGenerator.initQueryWrapper(cvResumeConvert.toEntity(params), request.getParameterMap());
        queryWrapper.eq("del_flag", false);
        if (StringUtils.isBlank(params.getField())) {
            queryWrapper.orderByAsc("lan_type");
        } else {
            queryWrapper.orderBy(true, params.getSort(), toUnderlineName(params.getField()));
        }
        IPage<CvResume> page = cvResumeService.page(params.page(), queryWrapper);
        Function<CvResume, CvResumeVO> fun = enInfo -> cvResumeConvert.toVO(enInfo);

        return Result.ok((Page) page.convert(fun));
    }

}
